/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q0119.java
 * @Author : WangRuoyu
 * @Date 2023/1/12 10:24
 */

package leetcode;

import java.util.ArrayList;
import java.util.List;

public class Q0119 {
    static int multi(int n, int m) {
        if ((n == 0) || (m - n) == 0) {
            return 1;
        } else {
            long res = 1;
            n = Math.min(n, m - n);
            for (int i = 1; i <= n; i++) {
                res *= m - i + 1;
                res /= i;
            }
            return (int) res;
        }
    }

    public List<Integer> getRow(int rowIndex) {
        List<Integer> res = new ArrayList<>();

        for (int i = 0; i <= rowIndex; i++) {
            res.add(multi(i, rowIndex));
        }

        return res;
    }

    public static void main(String[] args) {
        Q0119 sl = new Q0119();
        int n = 30;
        System.out.println(sl.getRow(n));
    }
}
